package com.cn.jx.manager.controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cn.jx.common.controller.BaseController;
import com.cn.jx.common.util.jpaQuery.ConvertCondition;
import com.cn.jx.common.util.jpaQuery.PageCondition;
import com.cn.jx.common.util.jpaQuery.QueryCondition;
import com.cn.jx.common.util.page.PageObj;
import com.cn.jx.manager.po.City;
import com.cn.jx.manager.po.DictData;
import com.cn.jx.manager.service.query.ICityServiceQry;
import com.jx.enumType.DataGrideTypeEnum;
import com.jx.util.Utility;

/**
 * 
 * @author 姜旭
 * @version v1.11.20.2019
 * @since 
 * <p>创建时间：2019年12月2日
 * <p>功能描述：字典读取
 * <p>官方网站：management/admin/index
 * <p>邮箱地址：524577360@qq.com
 */
@Controller
@RequestMapping("/admin/dictcity/")
public class DictController extends BaseController{
	
	private static final String _PAGE_PATH="dictcity/";
	
	/**
	 * 定义{@link String String <tt>定义key值</tt>}
	 * <p>map地图使用
	 */
	@Value("${amap.key}")
	private String key;
	
	/**
	 * 定义{@link String String <tt>定义version值</tt>}
	 * <p>map地图使用
	 */
	@Value("${amap.version}")
	private String version;
	
	/**
	 * 定义{@link ICityServiceQry cityServiceQry <tt>城市接口</tt>}
	 */
	@Autowired
	protected ICityServiceQry cityServiceQry;
	
	//============================================字典业务开头====================================================================
	/**
	* @Title: dictTolist
	* @Description: TODO(跳转到字典列表页面)
	* <p>邮箱地址：524577360@qq.com
	* @param model
	* @return
	* @return String 返回类型
	* @throws
	 */
	@RequestMapping("dict/list")
	public String dictTolist(Model model) {
		setModelColumns(model, DataGrideTypeEnum.DICT_TYPE);
		setModelColumns(model, DataGrideTypeEnum.DICT_DATA);
		return _PAGE_PATH + "dictlist";
	}
	 
	 /**
	 * @Title: dictyTypeList
	 * @Description: TODO(查询所有父字典类型)
	 * <p>邮箱地址：524577360@qq.com
	 * @throws
	  */
	@RequestMapping("dict/listTypeData/{path}")
	@ResponseBody
	public PageObj<DictData> dictyTypeList(Model model,@PathVariable(value = "path") String path, PageCondition page) {
		QueryCondition cond = ConvertCondition.initCondition(page, path);
		try {
			PageObj<DictData> pagedict = dictServiceQry.findDictDataByPageAndParams(cond);
			return pagedict;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	 @RequestMapping("getDict")
	 @ResponseBody
	 public List<DictData> getAllDictData(Model model,String dicType) {
		 return dictServiceQry.findDictByType(dicType);
	 }
	 
	 
	//============================================字典业务结束====================================================================
	
	//============================================城市业务开头====================================================================
	 /**
	 * @Title: cityTolist
	 * @Description: TODO(跳转页面跳转到城市列表页面)
	 * <p>邮箱地址：524577360@qq.com
	 * @param model
	 * @return
	 * @return String 返回类型
	 * @throws
	  */
	@RequestMapping("city/list")
	public String cityTolist(Model model) {
		model.addAttribute("key", key);
		model.addAttribute("version", version);
		model.addAttribute("rootCode", cityServiceQry.findChinaCode());
		setModelColumns(model, DataGrideTypeEnum.PROVINCE);
		setModelColumns(model, DataGrideTypeEnum.CITY);
		setModelColumns(model, DataGrideTypeEnum.DISTRICT);
		setModelColumns(model, DataGrideTypeEnum.COMMUNITY);
		return _PAGE_PATH + "citylist";
	}
	 
	 /**
	  * 
	 * @Title: cityList
	 * @Description: TODO(根据城市编码查询下属所有城市)
	 * <p>邮箱地址：524577360@qq.com
	 * @return List<City> 返回类型
	 * @throws
	  */
	@RequestMapping("city/listData")
	@ResponseBody
	public List<City> cityList(Model model, HttpServletRequest request, String code) {
		if (Utility.isBlank(code)) {
			return new ArrayList<City>();
		}
		return cityServiceQry.findAllCityByParent(code);
	}
//============================================城市业务结束====================================================================

}
